package cn.com.dycc.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.text.SimpleDateFormat;

import cn.com.dycc.sys_manage.logsysmanagement.entity.OperateLog;

public class Log {
	
	public static boolean addLog(OperateLog log){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    	Connection conn=null;
		try {
			conn=DBUtil.getConnection();
			String sql=""+
				"insert into t_operate_log "+
				"(                         "+
				"  user_id,                "+	  
				"  account,                "+
				"  username,               "+
				"  login_date,             "+
				"  ip,                     "+
				"  operate,                "+	  
				"  org_id,                 "+
				"  create_date,            "+
				"  result                  "+
				")                         "+
				"values(                   "+
				"  ?,                      "+  
				"  ?,                      "+
				"  ?,                      "+
				"  ?,                      "+
				"  ?,                      "+
				"  ?,                      "+	  
				"  ?,                      "+
				"  ?,                      "+
				"  ?                       "+
				") " ;
			PreparedStatement ps=conn.prepareStatement(sql);
			ps.setString(1, log.getUser_id());
			ps.setString(2, log.getAccount());
			ps.setString(3, log.getUsername());			
			ps.setString(4,sdf.format(log.getLogin_date()));			
			ps.setString(5, log.getIp());
			ps.setString(6, log.getOperate());
			ps.setString(7, log.getOrg_id());
			ps.setString(8,sdf.format(log.getCreate_date()));
			ps.setString(9, log.getResult());
			ps.executeUpdate();
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
			return false;			
		}finally{
			if(conn!=null){
				DBUtil.close();
			}
		}
    }

}
